package com.b2c.beans;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.b2c.entity.EticMarka;
import com.b2c.services.EticMarkaController;

@ManagedBean
@ViewScoped
public class MarkaGirisBean {
	private EticMarka eticMarka;
	private String markaAd;
	private List<EticMarka> markaList;

	private EticMarka selectedMarka;

	public MarkaGirisBean() {
		eticMarka = new EticMarka();
		refreshMarkaList();
	}

	public EticMarka getEticMarka() {
		return eticMarka;
	}

	public void setEticMarka(EticMarka eticMarka) {
		this.eticMarka = eticMarka;
	}

	public String getMarkaAd() {
		return markaAd;
	}

	public void setMarkaAd(String markaAd) {
		this.markaAd = markaAd;
	}

	public void markaObjEkle() {
		EticMarkaController markaController = new EticMarkaController();
		if (eticMarka.getId() == null) {
			markaController.markaEkle(eticMarka);
		} else {
			markaController.markaGuncelle(eticMarka);
		}
		eticMarka = new EticMarka();
		refreshMarkaList();
	}

	public void markaStrEkle() {
		EticMarkaController markaController = new EticMarkaController();
		markaController.markaEkle(markaAd);
	}

	public List<EticMarka> getMarkaList() {
		return markaList;
	}

	public void setMarkaList(List<EticMarka> markaList) {
		this.markaList = markaList;
	}

	public void refreshMarkaList() {
		EticMarkaController controller = new EticMarkaController();
		markaList = controller.getTumMarkalar();
	}

	public EticMarka getSelectedMarka() {
		return selectedMarka;
	}

	public void setSelectedMarka(EticMarka selectedMarka) {
		this.selectedMarka = selectedMarka;
	}

	public void markaSil() {
		EticMarkaController markaController = new EticMarkaController();
		markaController.markaSil(selectedMarka);
		refreshMarkaList();
	}

	public void markaOdakla() {
		eticMarka = selectedMarka;
	}

}
